<template>
  <div class="app-container">
    <el-card>
      <avue-form v-model="form" :option="option" @submit="handleSubmit">
        <template #avatar>
          <SingleImageUpload v-model="form.avatar" />
        </template>
      </avue-form>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { AdminModel } from "@/model/admin-model";
import adminAddOption from "./avue-options";
import AdminAPI from "@/api/system/admin";
import router from "@/router";

defineOptions({
  name: "AdminAdd",
});

/// 表单数据
const form = ref<AdminModel>({
  /** 姓名 */
  name: "陈某某",
  /** 头像 */
  avatar: "",
  /** 手机号 */
  mobile: "13320098527",
  /** 账号 */
  username: "13320098527",
  /** 密码 */
  password: "123456",
  /** 角色ID */
  auth_group_id: undefined,
  /** 状态 */
  status: 1,
});
const option = ref<Object>(adminAddOption);

/**
 * @description 表单提交
 * @param form 表单数据
 * @param done 完成函数
 */
const handleSubmit = (form: Object, done: Function) => {
  AdminAPI.add(form)
    .then(() => {
      ElMessage.success("操作成功");
      router.back();
    })
    .finally(() => {
      done();
    });
};

onMounted(() => {});
</script>

<style lang="scss" scoped></style>
